package com.servicesystem.servicesystem.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.servicesystem.servicesystem.entity.douyin.Subscription;
import com.servicesystem.servicesystem.mapper.SubscriptionMapper;
import com.servicesystem.servicesystem.service.SubscriptionService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author X
 * @version 1.0
 * @ClassName SubscriptionServiceImpl
 * @description
 * @date 2020/9/8
 **/
@Service
public class SubscriptionServiceImpl extends ServiceImpl<SubscriptionMapper, Subscription> implements SubscriptionService {

    /***
     * 订单消息订阅
     * @return
     */
    @Override
    public void orderSubscription(List<Map<String, Object>> subscriptionInfo) {
        for (Map<String, Object> map : subscriptionInfo) {
            Subscription subscription = new Subscription();
            String tag = (String) map.get("tag");
            subscription.setTag(tag);
            String msg_id = (String) map.get("msg_id");
            subscription.setMsgId(msg_id);
            String data = (String) map.get("data");
            Map dataMap = JSON.parseObject(data, Map.class);

            Object pId = dataMap.get("p_id");
            subscription.setPId(JSON.toJSONString(pId));
            Object sIds = dataMap.get("s_ids");
            subscription.setSIds(JSON.toJSONString(sIds));
            Object shopId = dataMap.get("shop_id");
            subscription.setShopId(JSON.toJSONString(shopId));
            Object orderStatus = dataMap.get("order_status");
            subscription.setOrderStatus(JSON.toJSONString(orderStatus));
            Object orderType = dataMap.get("order_type");
            subscription.setOrderType(JSON.toJSONString(orderType));
            Object createTime = dataMap.get("create_time");
            subscription.setCreateTime(JSON.toJSONString(createTime));
            Object biz = dataMap.get("biz");
            subscription.setBiz(JSON.toJSONString(biz));
            baseMapper.insert(subscription);

        }
    }
}
